import java.util.Arrays;
import java.util.Comparator;

public class Solution {
    public int intervalSchedule(int[][] intvs){
        if(intvs.length == 0){
            return 0;
        }
        Arrays.sort(intvs,new Comparator<int[]>(){
            public int compare(int[] a,int[] b){
                return a[1] - b[1];
            }
        });
        int count = 1;
        int x_end = intvs[0][1];
        for(int[] interval : intvs){
            int start = interval[0];
            if(start >= x_end){
                count++;
                x_end = interval[1];
            }
        }
        return count;
    }
}
